package sge.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sge.beans.Disciplina;
import sge.beans.Fachada;

public class DisciplinaServlet extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		String areaProfissional = req.getParameter("areaProfissional");
		String nomeCurso = req.getParameter("curso");
		String nomeDisciplina = req.getParameter("disciplina");

		Fachada fachada = Fachada.obterInstancia();
		Disciplina disciplina = new Disciplina();

		Long idArea = fachada.buscarIDArea(areaProfissional);
		disciplina.setIdArea(idArea);

		Long idCurso = fachada.buscarIDCurso(nomeCurso);
		disciplina.setIdCurso(idCurso);

		disciplina.setNomeDisciplina(nomeDisciplina);
		fachada.inserirDisciplina(disciplina);

		RequestDispatcher dispatcher = req.getRequestDispatcher(req
				.getContextPath()
				+ "/feedback/cadastro_efetuado.jsp");
		dispatcher.forward(req, resp);

	}
}
